/**
 * 已知如下数组：
  var arr = [
  [1, 2, 2],
  [3, 4, 5, 5],
  [6, 7, 8, 9, [11, 12, [12, 13, [14]]]], 10
];;
  编写一个程序将数组扁平化去并除其中重复部分数据，最终得到一个升序且不重复的数组
 */


var arr = [
  [1, 2, 2],
  [3, 4, 5, 5],
  [6, 7, 8, 9, [11, 12, [12, 13, [14]]]], 10
];



const _ = {

};

_.flattenV1 = arr => arr.flat(Infinity);

_.flattenV2 = arr => arr.toString().split(',').map(item => parseInt(item));

_.flattenV3 = (arr, res = []) => {
  for (let i = 0; i < arr.length; i++) {
    if (Array.isArray(arr[i])) {
      _.flattenV3(arr[i], res);
    } else {
      res.push(arr[i]);
    }
  }
  return res;
}

_.flattenV4 = arr => arr.reduce((pre, cur) => pre.concat(Array.isArray(cur) ? flatten(cur) : cur), []);

console.log(_.flattenV3(arr))